package com.roger.homecenterscreen.voice

import androidx.compose.ui.graphics.Color

/**
 * 语音状态扩展功能
 */

/**
 * 获取语音状态对应的主色调
 */
fun VoiceState.getPrimaryColor(): Color {
    return when (this) {
        VoiceState.IDLE -> Color.Gray
        VoiceState.LISTENING_WAKEUP -> Color.Blue
        VoiceState.WAKEUP_DETECTED -> Color.Yellow
        VoiceState.LISTENING_SPEECH, VoiceState.RECORDING, VoiceState.ASR_START, VoiceState.RECOGNIZING -> Color.Green
        VoiceState.PROCESSING -> Color(0xFFFFA500) // Orange
        VoiceState.SPEAKING -> Color.Cyan
        VoiceState.ERROR -> Color.Red
    }
}

/**
 * 获取语音状态对应的辅助色调
 */
fun VoiceState.getSecondaryColor(): Color {
    return getPrimaryColor().copy(alpha = 0.3f)
}

/**
 * 判断当前状态是否应该显示动画
 */
fun VoiceState.shouldAnimate(): Boolean {
    return when (this) {
        VoiceState.IDLE -> false
        VoiceState.LISTENING_WAKEUP -> true
        VoiceState.WAKEUP_DETECTED -> true
        VoiceState.LISTENING_SPEECH, VoiceState.RECORDING, VoiceState.ASR_START, VoiceState.RECOGNIZING -> true
        VoiceState.PROCESSING -> true
        VoiceState.SPEAKING -> true
        VoiceState.ERROR -> false
    }
}

/**
 * 获取状态对应的emoji图标
 */
fun VoiceState.getEmoji(): String {
    return when (this) {
        VoiceState.IDLE -> "💤"
        VoiceState.LISTENING_WAKEUP -> "👂"
        VoiceState.WAKEUP_DETECTED -> "⚡"
        VoiceState.LISTENING_SPEECH, VoiceState.RECORDING, VoiceState.ASR_START, VoiceState.RECOGNIZING -> "🎤"
        VoiceState.PROCESSING -> "⚙️"
        VoiceState.SPEAKING -> "🔊"
        VoiceState.ERROR -> "❌"
    }
}

/**
 * 获取详细的状态描述
 */
fun VoiceState.getDetailedDescription(): String {
    return when (this) {
        VoiceState.IDLE -> "语音助手休眠中，说出\"小平安\"来唤醒"
        VoiceState.LISTENING_WAKEUP -> "正在监听唤醒词\"小平安\""
        VoiceState.WAKEUP_DETECTED -> "唤醒成功！请开始说话"
        VoiceState.LISTENING_SPEECH -> "正在聆听您的话语..."
        VoiceState.RECORDING -> "正在录音..."
        VoiceState.ASR_START -> "开始识别..."
        VoiceState.RECOGNIZING -> "识别中..."
        VoiceState.PROCESSING -> "AI正在思考您的问题"
        VoiceState.SPEAKING -> "AI正在为您语音回答"
        VoiceState.ERROR -> "语音功能出现异常，正在自动恢复"
    }
}

/**
 * 判断状态是否为激活状态
 */
fun VoiceState.isActive(): Boolean {
    return this != VoiceState.IDLE && this != VoiceState.ERROR
}

/**
 * 判断状态是否需要用户交互
 */
fun VoiceState.requiresUserInput(): Boolean {
    return this == VoiceState.LISTENING_SPEECH || this == VoiceState.WAKEUP_DETECTED || this == VoiceState.RECORDING || this == VoiceState.ASR_START || this == VoiceState.RECOGNIZING
}

/**
 * 获取合成状态对应的描述
 */
fun SynthesisState.getDescription(): String {
    return when (this) {
        SynthesisState.IDLE -> "语音合成空闲"
        SynthesisState.SYNTHESIZING -> "正在生成语音..."
        SynthesisState.COMPLETED -> "语音播放完成"
        SynthesisState.ERROR -> "语音合成失败"
    }
}

/**
 * 判断合成状态是否为进行中
 */
fun SynthesisState.isInProgress(): Boolean {
    return this == SynthesisState.SYNTHESIZING
}